package com.wngbms.netty.book._06endec._03;

import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.embedded.EmbeddedChannel;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class Integer2ByteEncoderTest {

    public static void main(String[] args) {
        ChannelInitializer channelInitializer = new ChannelInitializer() {
            @Override
            protected void initChannel(Channel ch) throws Exception {
                ChannelPipeline pipeline = ch.pipeline();
                pipeline.addLast(new Integer2ByteEncoder());
            }
        };

        EmbeddedChannel channel = new EmbeddedChannel(channelInitializer);
        for (int i = 0; i < 100; i++) {
            channel.write(channel);
        }
        channel.flush();

        ByteBuf byteBuf = channel.readOutbound();
        while (byteBuf != null) {
            log.info("read:{}", byteBuf.readInt());
            byteBuf = channel.readOutbound();
        }
    }
}
